from sqlalchemy import Column, create_engine
# 类型bit,int,float
from sqlalchemy import Boolean, Integer, Float
# 文本类型 char,varchar
from sqlalchemy import String
# 时序类型
from sqlalchemy import DateTime
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

# 创建基类
Base = declarative_base()


class Employee(Base):
    # 表名
    __tablename__ = 'Employee'
    # 表结构
    id = Column(Integer(), primary_key=True, autoincrement=True)
    name = Column(String(20), index=True)
    age = Column(Integer())


# 创建数据库链接
engine = create_engine('mysql+pymysql://root:123@127.0.0.1:3306/orm')

# 创建session类
Session = sessionmaker(engine)
# 实例化session对象
session = Session()

p1 = Employee(name='cmy', age=18)
p2 = Employee(name='xiaoming', age=19)
session.add(p2)
session.add(p1)
session.commit()
session.close()
